# -*- encoding: utf-8 -*-
'''
@File    :   baidu_aip.py
@Time    :   2020/07/13 15:04:42
@Author  :   Song Zewen 
@Version :   1.0
@Contact :   stg1205@163.com
@License :   (C)Copyright 2020-2021, Liugroup-NLPR-CASIA
@Desc    :   百度NLP API测试
'''

import sys
import os
sys.path.append(os.environ.get('KEY_HOME'))

from aip_app import APP_ID, API_KEY, SECRET_KEY
from aip import AipNlp
from bs4 import BeautifulSoup
import crawler.crawler_util as cu


if __name__ == "__main__":
    
    # initilize app
    client = AipNlp(APP_ID, API_KEY, SECRET_KEY)

    title = '代码一键自动生成，拿走不谢'
    
    html = cu.get_html('https://blog.csdn.net/qq_16855077/article/details/105316295?utm_medium=distribute.pc_feed.none-task-blog-alirecmd-2.nonecase&depth_1-utm_source=distribute.pc_feed.none-task-blog-alirecmd-2.nonecase&request_id=')
    soup = BeautifulSoup(html, 'html.parser')
    content = cu.content_extractor(soup, 'csdn')
    
    items = client.keyword(title, content)['items']
    
    for item in items:
        print("score: {}, tag: {}".format(item['score'], item['tag']))
        
